<?php

namespace YmPhp\Admin\Http\Controllers;

use YmPhp\Admin\Http\Repositories\District;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class DistrictController extends AdminController
{

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new District(), function (Grid $grid) {
            $grid->column('id')->sortable();
//            $grid->column('pid');
            $grid->column('name');
            $grid->name->tree();
            $grid->order->orderable();
            $grid->column('level')->using(['1' => '省级', '2' => '市级', '3' => '区/县级', '4' => '乡/镇级', '5' => '街道/村级']);
            $grid->column('sort');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->showQuickEditButton();
            $grid->disableEditButton();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new District(), function (Show $show) {
            $show->field('id');
            $show->field('id');
            $show->field('pid');
            $show->field('name');
            $show->field('level');
            $show->field('usetype');
            $show->field('sort');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new District(), function (Form $form) {
            $form->display('id');
            $form->display('pid');
            $form->text('name');
            $form->text('level');
            $form->text('usetype');
            $form->text('sort');

        });
    }
}
